﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sekretar.Repository;

namespace Sekretar
{
    public partial class UcenikRecView : Common.Forms.RecView
    {
        int id;

        RUcenik rUcenik = new RUcenik();
        RMesto rMesto = new RMesto();
        RNacionalnost rNacionalnost = new RNacionalnost();
        RZanimanje rZanimanje = new RZanimanje();
        RStrucnaSprema rStrucnaSprema = new RStrucnaSprema();

        public UcenikRecView(int id)
        {
            InitializeComponent();
            this.id = id;
        }

        private void UcenikRecView_Load(object sender, EventArgs e)
        {
            bsMajkaStrucnaSprema.DataSource = rStrucnaSprema.VratiSve();
            bsMajkaZanimanje.DataSource = rZanimanje.VratiSveAktivne();
            bsMestoRodjenja.DataSource = rMesto.VratiSveAktivne();
            bsNacionalnost.DataSource = rNacionalnost.VratiSve();
            bsOtacStrucnaSprema.DataSource = rStrucnaSprema.VratiSve();
            bsOtacZanimanje.DataSource = rZanimanje.VratiSve();

            if (id == 0)
                bindingSource1.DataSource = rUcenik.Nov();
            else
                bindingSource1.DataSource = rUcenik.Izmeni(this.id);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                bindingSource1.EndEdit();
                this.Index = rUcenik.Snimi((DataLayer.Ucenik)bindingSource1.Current);
            }
            catch (Exception ex)
            {
                Common.Tools.MessageError.Show(ex.Message);
                this.DialogResult = DialogResult.None;
            }
        }
    }
}
